package com.slz3.business.frame.module;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.functions.Modify;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.UUID;

import static javax.persistence.EnumType.STRING;

@MappedSuperclass
@Data
public class DomainEntity implements Domain, Serializable {

    private static final long serialVersionUID = 6549429258070368585L;
    /**
     * 主键
     */
    @Id
//    @GeneratedValue
    @NotNull(message = "uuid must not null", groups = {Modify.class})
    private UUID uuid;

    /**
     * 上级【主键】
     */
    @Null(message = "upper 必须为空!", groups = {Modify.class})
    private UUID upper;

    /**
     * 逻辑删除标识
     */
    @Enumerated(STRING)
    @Column(length = 5, nullable = false)
//    @Null(message = "validFlag 必须为空!", groups = {Modify.class})
    private ValidFlag validFlag = ValidFlag.VALID;

    /**
     * 创建者【主键】
     */
    @Null(message = "creator 必须为空!", groups = {Modify.class})
    private UUID creator;

    /**
     * 创建时间
     */
//    @Null(message = "createTime 必须为空!", groups = {Modify.class})
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    private LocalDateTime createTime;

    /**
     * 创建者 IP
     */
    @Null(message = "creatorIp 必须为空!", groups = {Modify.class})
    private String creatorIp;

    /**
     * 最后修改者【主键】
     */
    @Null(message = "lastModifier 必须为空!", groups = {Modify.class})
    private UUID lastModifier;

    /**
     * 最后修改时间
     */
    @Null(message = "lastModifyTime 必须为空!", groups = {Modify.class})
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss.SSS")
    private LocalDateTime lastModifyTime;

    /**
     * 最后修改者 IP
     */
    @Null(message = "lastModifierIp 必须为空!", groups = {Modify.class})
    private String lastModifierIp;

    /**
     * 所属组织【主键】
     */
    @Null(message = "ownerOrganize 必须为空!", groups = {Modify.class})
    private UUID ownerOrganize;

    /**
     * 所属角色【主键】
     */
    @Null(message = "ownerRole 必须为空!", groups = {Modify.class})
    private UUID ownerRole;




}
